package org.example.niceoil.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.example.niceoil.entity.Customer;
import org.example.niceoil.entity.Manager;
import org.example.niceoil.mapper.ManagerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/logining")
public class LoginController {
    @Autowired
    private ManagerMapper ManagerMapper;

    @PostMapping("/login")
    public String login(@RequestBody Map<String, String> loginData) {
        String is = "no";
        String username = loginData.get("maname");
        String password = loginData.get("mapassword");

        System.out.println("用户名：" + username);
        System.out.println("密码：" + password);

        QueryWrapper<Manager> query = new QueryWrapper<>();
        query.eq("maname", username); // 不等于

        Manager manager = ManagerMapper.selectOne(query);
        if (manager == null) {
            // 这里表示不存在该 username 的数据
            return "noexist";
        } else if (password.equals(manager.getMapassword())) {
            is = "yes";
            System.out.println(is + "=========");
            return is;
        }

        return is;
    }
}
